#Requires AutoHotkey v2.0
#Include "func.ahk"

; 登录初始化

SetWinDelay 200
SetControlDelay 100
Sleep 2000
; 如果启动了PortableApps，则需重启资源管理器
;ProcessClose "explorer.exe"

; 7tt在"7+后面不知道有个什么字符"
if WinExist("7+.*Taskbar.*Tweaker") {
	WinClose "7+.*Taskbar.*Tweaker"
}
if WinExist("Everything") {
	WinClose "Everything"
}
; vivo办公套件执行WM_CLOSE后会关闭进程
if WinExist("ahk_exe pcsuite.exe") {
	WinMinimize "ahk_exe pcsuite.exe"
}
; Thunderbird 启动时没有最小化
if WinExist("ahk_exe thunderbird.exe") {
	WinMinimize "ahk_exe thunderbird.exe"
}
if WinExist("Jami") {
	WinClose "Jami"
}

; 自动登录
Sleep 3000
; 思源笔记
if WinExist("ahk_exe SiYuan.exe") {
	ControlClick , "ahk_exe SiYuan.exe",,,, "NA X" getRelativePos("ahk_exe SiYuan.exe", 50) "Y" getRelativePos("ahk_exe SiYuan.exe",, 50)
;	inputStr(getAppInfo("siyuan", "password"))
;	Send "{Enter}"
	ControlSend getAppInfo("siyuan", "password") "{Enter}"
}
if WinExist("ahk_exe qtox.exe") {
	ControlClick , "ahk_exe qtox.exe",,,, "NA X210 Y116"
	ControlSend getAppInfo("qtox", "password") "{Enter}"
}
; QQ
if WinExist("QQ") {
	Sleep 1500
	ControlClick , "QQ",,,, "NA X160 Y332"
	if (WinWaitClose("QQ",, 10)) {
		if WinWait("QQ",, 10) {
			Sleep 2000
			WinClose "QQ"
		}
	}
}
; 微信
;if WinExist("ahk_class WeChatLoginWndForPC") {
;	ControlClick , "ahk_class WeChatLoginWndForPC",,,, "NA X136 Y288"
;	if WinWait("ahk_class WeChatMainWndForPC",, 10) {
;		WinClose "ahk_class WeChatMainWndForPC"
;	}
;}

; 千牛工作台
if WinExist("千牛登录") {
	Sleep 1500
;	ControlClick "x530 y250", "千牛登录",,,, "X530 Y250"
;	Send "^a"
;	inputStr(getAppInfo("AliWorkbench", "username_c"))
;	Send "{Enter}"
;	ControlClick "x530 y300", "千牛登录",,,, "X530 Y300"
;	inputStr(getAppInfo("AliWorkbench", "password_c"))
	ControlClick "x530 y449", "千牛登录",,,, "NA X530 Y449"
}

SetWinDelay 100
SetControlDelay 20